﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;

namespace MINERP.DAL.InfoConfig
{
    public class ShopDAL:DALBase
    {
        //private static  ObjectQuery<Shop> GetShops()
        //{
        //    return DataEntites.Shop.Where("it.Status <>0");
        //}


        /// <summary>
        /// Get Shop list
        /// </summary>
        /// <returns></returns>
        //public static List<Shop> GetShopList()
        //{
        //    List<Shop> list = new List<Shop>();
        //    foreach (Shop shop in GetShops())
        //    {
        //        list.Add(shop);
        //    }
        //    return list;
        //}

        /// <summary>
        /// Get shop object by id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Shop GetShopObj(int id)
        {
            return DataEntites.Shop.Include("Shop_Product_Price").First(s => s.ShopId == id);
        }
        /// <summary>
        /// Get shop object by name
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static Shop GetShopObj(string name)
        {
            return DataEntites.Shop.FirstOrDefault(s => s.shopName==name&&s.Status ==1);
        }
        /// <summary>
        /// Add shop
        /// </summary>
        /// <param name="obj"></param>
        public static void AddShop(Shop obj)
        {
            DataEntites.AddToShop(obj);
            DataEntites.SaveChanges();
        }
        /// <summary>
        /// Update shop
        /// </summary>
        /// <param name="obj"></param>
        public static void UpdateShop()
        {
            DataEntites.SaveChanges();
        }

        /// <summary>
        /// Delete shop
        /// </summary>
        /// <param name="obj"></param>
        public static void DeleteShop(Shop obj)
        {
            Shop shop = DataEntites.Shop.First(s => s.ShopId == obj.ShopId);
            DataEntites.DeleteObject(shop);
            DataEntites.SaveChanges();
        }

        public static Shop GetShopOnly(int id)
        {
            return DataEntites.Shop.FirstOrDefault(s => s.ShopId == id);
        }
    }
}
